
export default function (Page) {
    // 返回一个新的 Page 构造器
    return (function (page) {

        // 获取需要hook的方法, 保存方法的原始实现
        const {onLoad, onShow, onShareAppMessage, onShareTimeline} = page;
        /*重写onShareAppMessage*/
        if (typeof onShareAppMessage === "function") {
            page.onShareAppMessage = function (res) {
                let data = onShareAppMessage.call(this) || {};
                if (Object.keys(data).length > 0) {
                    return data
                } else {
                    return {
                        title: "汇鸿汇升",
                        path: "/pages/home/index/index"
                    }
                }
            }
        }

        /*重写onShareTimeline*/
        if (typeof onShareTimeline === "function") {
            page.onShareTimeline = function (res) {
                let data = onShareTimeline.call(this) || {};
                if (Object.keys(data).length > 0) {
                    return data
                } else {
                    return {
                        title: "汇鸿汇升",
                        path: "/pages/home/index/index"
                    }
                }
            }
        }

        // 调用原来的构造方法
        return Page(page);
    });
}